package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.AddSuperviseDto;
import com.ruoyi.system.domain.vo.SysSupervisionPlanVo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSupervisionPlan;
import com.ruoyi.system.service.ISysSupervisionPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 督查计划Controller
 * 
 * @author ruoyi
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/system/supervisePlan")
public class SysSupervisionPlanController extends BaseController
{
    @Autowired
    private ISysSupervisionPlanService sysSupervisionPlanService;

    /**
     * 查询督查计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSupervisionPlan sysSupervisionPlan)
    {
        startPage();
        List<SysSupervisionPlanVo> list = sysSupervisionPlanService.selectSysSupervisionPlanList(sysSupervisionPlan);
        return getDataTable(list);
    }

    /**
     * 导出督查计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "督查计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSupervisionPlan sysSupervisionPlan)
    {
        List<SysSupervisionPlanVo> list = sysSupervisionPlanService.selectSysSupervisionPlanList(sysSupervisionPlan);
        ExcelUtil<SysSupervisionPlanVo> util = new ExcelUtil<SysSupervisionPlanVo>(SysSupervisionPlanVo.class);
        util.exportExcel(response, list, "督查计划数据");
    }

    /**
     * 获取督查计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(sysSupervisionPlanService.selectSysSupervisionPlanByPlanId(planId));
    }

    /**
     * 新增督查计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "督查计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSupervisionPlan sysSupervisionPlan)
    {
        return toAjax(sysSupervisionPlanService.insertSysSupervisionPlan(sysSupervisionPlan));
    }

    /**
     * 修改督查计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "督查计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSupervisionPlan sysSupervisionPlan)
    {
        return toAjax(sysSupervisionPlanService.updateSysSupervisionPlan(sysSupervisionPlan));
    }

    /**
     * 删除督查计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "督查计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(sysSupervisionPlanService.deleteSysSupervisionPlanByPlanIds(planIds));
    }

    @PostMapping("/batch_add")
    public AjaxResult batchAdd(@RequestBody AddSuperviseDto dto){
        return sysSupervisionPlanService.batchAdd(dto);
    }

}
